package com.jike.noobmoney;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.StrictMode;
import android.support.multidex.MultiDexApplication;

import com.bumptech.glide.request.target.ViewTarget;
import com.duoyou.ad.openapi.DyAdApi;
import com.iBookStar.views.YmConfig;
import com.image.imagepicker.ImagePicker;
import com.jike.noobmoney.util.AbContextUtils;
import com.jike.noobmoney.util.CrashHandler;
import com.jike.noobmoney.util.ImagePickerLoader;
import com.liulishuo.filedownloader.FileDownloader;
import com.lz.aiwan.littlegame.utils.LzLittleGame;
import com.lz.aiwan.littlegame.utils.TTAdManagerHolder;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.pgyersdk.crash.PgyCrashManager;
import com.tencent.bugly.crashreport.CrashReport;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;

import cn.jiguang.analytics.android.api.JAnalyticsInterface;
import cn.jpush.android.api.JPushInterface;

/**
 * 作者：bingo on 2017/10/26
 * 作用：Application
 */
public class MyApplication extends MultiDexApplication {

    private static MyApplication instance;

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public int flag;

    public static MyApplication getInstance() {
        return instance;
    }

    @SuppressLint("NewApi")
    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        AbContextUtils.init(this);
        FileDownloader.setup(this);

        //初始化我玩小游戏sdk
        LzLittleGame.getInstance().init(this);
        //穿山甲sdk初始化
        TTAdManagerHolder.init(this,"5042247");    //如果本身已经集成穿山甲sdk，无需重复初始化

        ViewTarget.setTagId(R.id.tag_glide);
        initImageLoader(getApplicationContext());
        //友盟
        UMConfigure.init(this, "5bc7020eb465f53dc70002b8", BuildConfig.FLAVOR_NAME .equals("app")  ? "Umeng" : BuildConfig.FLAVOR_NAME, UMConfigure.DEVICE_TYPE_PHONE, "");
        UMConfigure.setLogEnabled(true);
        //微信分享
        //PlatformConfig.setWeixin("wx535a11559e5c98cc", "f94a1b50de4b48239741f50d7f6c913c");
        //PlatformConfig.setWeixin("wxeacd5c31a7cfcb2c", "01783d83960b0a47b596e9028b836562");
        PlatformConfig.setWeixin("wxeacd5c31a7cfcb2c", "8c208edc16c5f19b0f7197c7aba5321d");
        //QQ分享
        //PlatformConfig.setQQZone("101509567", "82db0834836a38a447844fb565576e58");
        PlatformConfig.setQQZone("101509303", "3b929b4b3a23653d5dec55fc1ca0756f");
        //bugly
        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(this);
        CrashReport.initCrashReport(this, "0b6ce60a43", true, strategy);
        //蒲公英
        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());
        PgyCrashManager.register(this);
        //极光
        JPushInterface.init(this);
        JPushInterface.setDebugMode(true);
        JAnalyticsInterface.init(this);
        JAnalyticsInterface.setDebugMode(true);
        //多游
        DyAdApi.getDyAdApi().init("dy_59611133", "0d6e5952fe9f5e70321a8aac9f162690");

        //阅读
        YmConfig.initNovel(this, "8201");
        initImagePicker();

        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();

        FileDownloader.setup(this);

    }

    public static void initImageLoader(Context context) {
        // This configuration tuning is custom. You can tune every option, you may tune some of them,
        // or you can create default configuration by
        //  ImageLoaderConfiguration.createDefault(this);
        // method.
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .writeDebugLogs() // Remove for release app
                .build();
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
    }

    private void initImagePicker() {
        ImagePicker imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new ImagePickerLoader());   //设置图片加载器
        imagePicker.setShowCamera(true);                      //显示拍照按钮
        //imagePicker.setCrop(true);                            //允许裁剪（单选才有效）
        imagePicker.setSaveRectangle(true);                   //是否按矩形区域保存
        imagePicker.setSelectLimit(9);                        //选中数量限制
        //imagePicker.setStyle(CropImageView.Style.RECTANGLE);  //裁剪框的形状
        //imagePicker.setFocusWidth(800);                       //裁剪框的宽度。单位像素（圆形自动取宽高最小值）
        //imagePicker.setFocusHeight(800);                      //裁剪框的高度。单位像素（圆形自动取宽高最小值）
        imagePicker.setOutPutX(1000);                         //保存文件的宽度。单位像素
        imagePicker.setOutPutY(1000);                         //保存文件的高度。单位像素
    }


}